<template>
  <div class="box">
    <van-nav-bar
      title="发票抬头"
      left-text=""
      left-arrow
      @click-left="onClickLeft"
    />
    <RouterLink to="/add">
      <van-button type="primary" size="large" icon="plus" plain
        >新增发票抬头</van-button
      ></RouterLink
    >
    <div class="center">
      <div
        class="list"
        v-for="(item, index) in data.list"
        :key="index"
        @click="editlist(item.id)"
      >
        <div class="left">
          <p class="name">{{ item.name }}</p>
          <div class="xia">
            <span>{{ item.type }}</span>
            <span v-if="item.defaults == 1">默认</span>
          </div>
        </div>
        <div class="right">&gt;</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, reactive } from "vue";
import { getRess } from "../api/api";
import { useRouter } from "vue-router";

const router = useRouter();

// 数据
let data: any = reactive({
  list: [],
});

// 获取数据渲染
onMounted(async () => {
  await getRess().then((res) => {
    data.list = res.data.data;
  });
});

// 点击返回
const onClickLeft = () => {
  router.push("/login");
};

// 点击修改
const editlist = (id: number) => {
  router.push({
    path: "/add",
    query: { id },
  });
};
</script>

<style scoped>
.goods-card {
  margin: 0;
  background-color: #fff;
  height: 60px;
}

.delete-button {
  height: 100%;
}
* {
  padding: 0;
  margin: 0;
  overflow: hidden;
}
.box {
  background-color: #f2f2f2;
  height: 100vh;
}
.van-button {
  width: 95%;
  height: 45px;
  margin: 10px;
  border: none;
}
a {
  color: rgb(0, 149, 198);
}
.center {
  width: 95%;
  /* background-color: white; */
  margin: 0 auto;
  height: calc(100vh - 120px);
  overflow: auto;
}
.list {
  overflow: hidden;
  width: 100%;
  background-color: white;
  height: 60px;
  border-radius: 10px;
  margin-top: 10px;
}
.left {
  float: left;
  /* display: flex; */
}
.name {
  font-size: 16px;
  margin: 10px;
}
.xia {
  margin: 10px;
  margin-top: -5px;
}
.xia > span {
  display: inline-block;
  /* width: 30px; */
  height: 15px;
  border: 2px solid #a1a1a1;
  line-height: 15px;
  text-align: center;
  border-radius: 5px;
  color: #979797;
  margin-right: 5px;
  font-size: 11px;
  padding: 0 3px;
}
.right {
  float: right;
  font-size: 20px;
  color: #979797;
  line-height: 60px;
  margin-right: 15px;
}
</style>